﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPNETPerformance.App_BusinessLogic.BasePages;
using Yahoo.Yui.Compressor;

namespace ASPNETPerformance._02_JsAndCss {
    public partial class MinCompression : BasePage {
        protected void Page_Load( object sender, EventArgs e ) {
            if ( !this.Page.IsPostBack ) {
                string cssContent = File.ReadAllText(Server.MapPath("~/_assets/css/CustomStyles.css"));
                this.txtBytesInCSSContent.Text = cssContent;
                this.lblBytesInCSSContent.Text = this.txtBytesInCSSContent.Text.Length.ToString( "N0" );
                this.txtBytesInCSSContentByCompressor.Text = CssCompressor.Compress( cssContent );
                this.lblBytesInCSSContentByCompressor.Text = this.txtBytesInCSSContentByCompressor.Text.Length.ToString( "N0" );

                string javascriptContent = File.ReadAllText( Server.MapPath( "~/_assets/js/public.js" ) );
                this.txtBytesInJavascriptContent.Text = javascriptContent;
                this.lblBytesInJavascriptContent.Text = this.txtBytesInJavascriptContent.Text.Length.ToString( "N0" );
                this.txtBytesInJavascriptContentByCompressor.Text = JavaScriptCompressor.Compress( javascriptContent );
                this.lblBytesInJavascriptContentByCompressor.Text = this.txtBytesInJavascriptContentByCompressor.Text.Length.ToString( "N0" );
            }
        }
    }
}